//
//  ImageEffectsViewController.m
//  模糊效果
//
//  Created by yq on 2022/6/16.
//

#import "ImageEffectsViewController.h"
#import "UIImage+ImageEffects.h"

@interface ImageEffectsViewController ()
@property (nonatomic, strong) UIImageView *iv;
@end

@implementation ImageEffectsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"ImageEffects";
    //https://github.com/YouXianMing/UIImageBlur
    
    UIImage *image = [UIImage imageNamed:@"cat.jpg"];
    UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 640 * 0.5, 1024 * 0.5)];
    iv.image = image;
    
    [self.view addSubview:iv];
    self.iv = iv;
}

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    self.iv.center = self.view.center;
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    UIImage *image = [UIImage imageNamed:@"cat.jpg"];
    static int i = 0;
    UIImage *blurImage = nil;
    if (i == 0) {
        blurImage = [image blurImage];
    }else if (i == 1) {
        blurImage = [image blurImageAtFrame:(CGRectMake(self.view.center.x, self.view.center.x, 300, 200))];
    }else if (i == 2) {
        blurImage = [image grayScale];
    }else {
        i = -1;
        blurImage = image;
    }
    self.iv.image = blurImage;
    i++;
}
@end
